//#include <functional>
//#include <iostream>
//#include <list>
//#include <mutex>
//#include <shared_mutex>
//#include <unistd.h>
//#include <vector>
//#include <chrono>
//#include <memory>
//#include <algorithm>
//#include <cassert>
//#include "../lib/timer-wheel/timer-wheel.h"
//#include "../lib/wrrmmap/WRRMMap.h"
//
//std::mutex m_mutex;
//bool keepRunning = true;  // 添加标志位来控制循环
//
//
//
//long long getCurrentTimestampMillis() {
//    auto now = std::chrono::system_clock::now();
//    auto duration = now.time_since_epoch();
//    auto millis = std::chrono::duration_cast<std::chrono::milliseconds>(duration).count();
//    return millis;
//}
//
//int main() {
//    typedef std::function<void()> Callback;
//    TimerWheel timers;
//    int task_num = 120;
//    Tick unit = 20 * 1000;
//    Tick taskDuration = unit / task_num;
//
//    WRRMMap<int, std::shared_ptr<TimerEvent<Callback>>> timerMap;
//
//
//
//    Tick start = getCurrentTimestampMillis();
//    {
//        std::lock_guard<std::mutex> lock(m_mutex);  // 加锁
//        for (int i = 0; i < task_num; ++i) {
//            std::shared_ptr<TimerEvent<Callback>> timer = std::make_shared<TimerEvent<Callback>>([&timers, &timerMap, &task_num, &unit, &start, i](TimerWheel* timerWheel){
//                std::lock_guard<std::mutex> lock(m_mutex);  // 加锁
//                if (timerMap.Contain(i)) {
//                    std::shared_ptr<TimerEvent<Callback>> timer;
//                    timerMap.Lookup(i, timer);
//                    timers.schedule(&*(timer), unit);
//                }
//                std::cout << "time-" << i << ": " << getCurrentTimestampMillis() - start << "ms"
//                        << " task_num = " << task_num << " unit: " << unit << std::endl;
//            });
//            timerMap.Update(i, timer);
//            timers.schedule(&*timer, taskDuration * (i+1));
//            std::cout << "添加任务:" << i << std::endl;
//        }
//    }  // 锁在此处释放
//
//    start = getCurrentTimestampMillis();
//    while (keepRunning) {  // 使用标志位控制循环
//        timers.advance(10);
//        usleep(1000);
//    }
//
//    return 0;
//}
